import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Waffen here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Waffe extends Actor
{
    /**
     * Act - do whatever the Waffen wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    int typ;
    double Rm;//Recihweitemulti
    double Sm;//Schadensmutli
    int AReich;
    int ASchade;
    int Schuss;
    boolean flieg;
    Held H = null;
    public Waffe(int WFtyp,double rm, double sm){
        typ = WFtyp;
        Rm = rm;
        Sm = sm;

    }
    public void act(){
        img();
        
        if(H != null){
            if(flieg == true){
                Schuss();
                AReich = AReich -1;
                if(AReich == 0){

                    Welt W1 = (Welt) getWorld();
                    W1.removeObject(this);
                    return;
                }
            }
        }
        Schadöner();
    }

    private void img()
    {
        if(typ == 5)
        {
            setImage("Säureball.png");
        }
        else if(typ == 1)
        {
            setImage("schraubenschlüssel.png");
        }
        else if(typ == 2)
        {
            setImage("Wasserball.png");
        }
        else if(typ == 3)
        {
            setImage("Feuerball.png");
        }
        else if(typ == 4)
        {
            setImage("rocket.png");
        }
    }

    public void angriffsanimation(Held A){
        H = A;
        AReich = (int)(Rm*A.Rw);
        ASchade = (int)(Sm*A.ATK);
        if(A.BR == 1){
            Schuss = 5;

        }
        if(A.BR == -1){
            Schuss = -5;

        }
        flieg = true;

    }

    public void Schuss(){
        setLocation(getX()+Schuss,getY());
        if(typ!=4)
        {
            setRotation(getRotation()+10);
        }

    }
    
    public void Schadöner(){
        Gegner G = (Gegner) getOneIntersectingObject(Gegner.class);
        
        if(G!=null){
            G.hit(ASchade);
            AReich = 0;
            Welt W1 = (Welt) getWorld();
            W1.removeObject(this);
            return;
        }
        
    }
}
